package com.harzone.commons.search.utils;

import java.util.List;
import java.util.Map;

import com.harzone.commons.search.domain.KeyValue;

public class SearchUtil {
	
	
	public static String joiner(List<KeyValue> lists, String oper) {
		
		if (lists == null || lists.size() == 0) {
			return "";
		}

		StringBuilder sb = new StringBuilder(lists.get(0).toString());
		for (int i = 1; i < lists.size(); i++) {
			sb.append(oper);
			sb.append(lists.get(i).toString());
		}

		return sb.toString();
	}

	public static List<Map<String, Object>> sortByMap(List<Map<String, Object>> lists) {

		return lists;
	}


	public static double[] String2DoubleArr(String paramer) {
		String[] split = paramer.split(",");
		double[] ds = new double[split.length];
		for (int i = 0; i < ds.length; i++) {
			ds[i] = Double.parseDouble(split[i].trim());
		}
		return ds;
	}

	public static double[] KV2DoubleArr(List<KeyValue> params) {
		double[] ds = new double[params.size()];
		int i = 0;
		for (KeyValue v : params) {
			ds[i] = ((Number) v.value).doubleValue();
			i++;
		}
		return ds;
	}

}
